﻿<?xml version="1.0" encoding="utf-8" ?>
<!--namespace必须用否者就报错（读取配置文件报：未将对象引用设置到对象的实例）-->
<sqlMap namespace="" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <statements>
    <![CDATA[分类]]>
    <!--分类操作开始-->
    <!--添加分类-->
    <insert id="InsertCategory" parameterClass="HashTable" resultClass="int">
      INSERT INTO [CMS_Category]
      ([CategoryCode]
      ,[CategoryName]
      ,[ParentId]
      ,[Sequence]
      ,[CategoryImg]
      ,[CategoryUrl]
      ,[ContentCount]
      ,[CategoryDesc]
      ,[SeoTitle]
      ,[SeoH1]
      ,[SeoDes]
      ,[CreateMan]
      ,[CreateTime])
      VALUES
      (#CategoryCode#,
      #CategoryName#,
      #ParentId#,
      #Sequence#,
      #CategoryImg#,
      #CategoryUrl#,
      #ContentCount#,
      #CategoryDesc#,
      #SeoTitle#,
      #SeoH1#,
      #SeoDes#,
      #CreateMan#,
      #CreateTime#)
    </insert>
    <update id="UpdateCategory" parameterClass="HashTable" resultClass="int">
      UPDATE [CMS_Category]
      SET [CategoryCode] =#CategoryCode#
      ,[CategoryName] =#CategoryName#
      ,[ParentId] =#ParentId#
      ,[Sequence] =#Sequence#
      ,[CategoryImg] =#CategoryImg#
      ,[CategoryUrl] =#CategoryUrl#
      ,[ContentCount] =#ContentCount#
      ,[CategoryDesc] =#CategoryDesc#
      ,[SeoTitle] =#SeoTitle#
      ,[SeoH1] =#SeoH1#
      ,[SeoDes] =#SeoDes#
      ,[CreateMan] =#CreateMan#
      ,[CreateTime] =#CreateTime#
      WHERE Id=#Id#
    </update>
    <delete id="DeleteCategory" parameterClass="string" resultClass="int">
      delete from [CMS_Category]
      where  [Id] = #Id#

      delete from [CMS_Category] where [CategoryId] = #Id#
    </delete>
    <delete id="DeleteCategoryList" parameterClass="string" resultClass="int">
      delete from [CMS_Category] where Id in
      <iterate   property="IdList" open="(" close=")"  conjunction=",">
        #IdList[]#
      </iterate>
    </delete>

    <select id="GetCategoryAll" resultClass="HashTable">
      SELECT   *,ParentId as _parentId
      FROM [CMS_Category]
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty prepend="and" property="CategoryParentCode">
            CategoryParentCode =  '$CategoryParentCode$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
      order by Sequence asc,id asc
    </select>

    <select id="GetCategoryTreeList" resultClass="HashTable">
      SELECT   *
      FROM [Category] where CategoryParentCode= #CategoryParentCode# order by Sequence asc,id asc
    </select>


    <select id="GetCategory" parameterClass="string" resultClass="Kaiser.Modules.CMS.Models.CategoryInput">
      SELECT  *  FROM [CMS_Category] WHERE Id=#Id#
    </select>
    <!--分类操作结束-->
    <![CDATA[内容]]>
    <![CDATA[标签]]>
  </statements>
  <statements>

    <select id="QueryContent" resultClass="HashTable">
      select *,CategoryId as listCategoryContentInput from CMS_V_CategoryContent
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty prepend="and" property="Code">
            CategoryId =  '$Code$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>

    <select id="GetContentById" parameterClass="string" resultClass="Kaiser.Modules.CMS.Models.ContentInput">
      SELECT     CategoryId, ContentId AS Id, Code, EnglishTitle, EnglishContent, Author, TitleShort, EnglishShort, ContentTitle, SecondTitle, ContentSummary, ContentKeywords,
      ContentUrl, SourceDerivation, SourceAuthor, SourceUrl, ContentDetail, EnglishDetail, IsRecommend, ClickCount, IsDelete, CreateTime, UpdateTime, Area, Groom,
      TopLine, Hot, Stick, Cream, Roll, CategoryCode, CategoryName, ParentId, Sequence, CategoryImg, CategoryUrl, ContentCount, CategoryDesc, SeoTitle, SeoH1,
      SeoDes, CAST(CategoryId AS varchar) AS listCategoryContentInput
      FROM         CMS_V_CategoryContent
      where Id =  $value$
    </select>

    <insert id="InsertContent" parameterClass="HashTable" resultClass="int">
      INSERT INTO [CMS_Content]
      ([EnglishTitle]
      ,[EnglishContent]
      ,[Author]
      ,[TitleShort]
      ,[EnglishShort]
      ,[ContentTitle]
      ,[SecondTitle]
      ,[ContentSummary]
      ,[ContentKeywords]
      ,[ContentUrl]
      ,[SourceDerivation]
      ,[SourceAuthor]
      ,[SourceUrl]
      ,[ContentDetail]
      ,[EnglishDetail]
      ,[IsRecommend]
      ,[ClickCount]
      ,[IsDelete]
      ,[CreateTime]
      ,[UpdateTime]
      ,[Area]
      ,[groom]
      ,[topLine]
      ,[hot]
      ,[stick]
      ,[cream]
      ,[roll]
      ,Code)
      VALUES
      (#EnglishTitle#
      ,#EnglishContent#
      ,#Author#
      ,#TitleShort#
      ,#EnglishShort#
      ,#ContentTitle#
      ,#SecondTitle#
      ,#ContentSummary#
      ,#ContentKeywords#
      ,#ContentUrl#
      ,#SourceDerivation#
      ,#SourceAuthor#
      ,#SourceUrl#
      ,#ContentDetail#
      ,#EnglishDetail#
      ,#IsRecommend#
      ,#ClickCount#
      ,#IsDelete#
      ,#CreateTime#
      ,#UpdateTime#
      ,#Area#
      ,#groom#
      ,#topLine#
      ,#hot#
      ,#stick#
      ,#cream#
      ,#roll#
      ,#Code#
      )
      <selectKey resultClass="int" Property="Id" type="post">
        SELECT @@IDENTITY AS value
      </selectKey>
    </insert>

    <update id="UpdateContent" parameterClass="HashTable" resultClass="int">
      UPDATE [CMS_Content]
      SET [EnglishTitle]=#EnglishTitle#
      ,[EnglishContent]=#EnglishContent#
      ,[Author]=#Author#
      ,[TitleShort]=#TitleShort#
      ,[EnglishShort]=#EnglishShort#
      ,[ContentTitle]=#ContentTitle#
      ,[SecondTitle]=#SecondTitle#
      ,[ContentSummary]=#ContentSummary#
      ,[ContentKeywords]=#ContentKeywords#
      ,[ContentUrl]=#ContentUrl#
      ,[SourceDerivation]=#SourceDerivation#
      ,[SourceAuthor]=#SourceAuthor#
      ,[SourceUrl]=#SourceUrl#
      ,[ContentDetail]=#ContentDetail#
      ,[EnglishDetail]=#EnglishDetail#
      ,[IsRecommend]=#IsRecommend#
      ,[ClickCount]=#ClickCount#
      ,[IsDelete]=#IsDelete#
      ,[CreateTime]=#CreateTime#
      ,[UpdateTime]=#UpdateTime#
      ,[Area]=#Area#
      ,[groom]=#groom#
      ,[topLine]=#topLine#
      ,[hot]=#hot#
      ,[stick]=#stick#
      ,[cream]=#cream#
      ,[roll]=#roll#
      ,[Code]=#Code#
      WHERE Id=#Id#
    </update>
    <delete id="DeleteContent" parameterClass="string" resultClass="int">
      DELETE FROM [CMS_Content]
      where  [Id] = #Id#
    </delete>

    <delete id="DeleteContentList" parameterClass="string" resultClass="int">
      BEGIN  
      delete from [CMS_Content] where Id in (select ContentId from dbo.CMS_CategoryContent where [id] in
      <iterate  open="(" close=")"  conjunction=",">
        #[]#
      </iterate>
      );
      delete CMS_CategoryContent where [id] in   
      <iterate  open="(" close=")"  conjunction=",">
        #[]#
      </iterate>; 
      END;
    </delete>

    <insert id="InsertCategoryContent" parameterClass="HashTable" resultClass="int">
      INSERT INTO [CMS_CategoryContent]
      ([CategoryId]
      ,[ContentId])
      VALUES
      (#CategoryId#
      ,#ContentId#)
    </insert>

    <update id="UpdateCategoryContent" parameterClass="HashTable" resultClass="int">
      UPDATE [CMS_CategoryContent]
      SET [CategoryId] =#CategoryId#
      ,[ContentId] = #ContentId#
      WHERE Id=#Id#
    </update>
    <delete id="DeleteCategoryContent" parameterClass="string" resultClass="int">
      DELETE FROM [CMS_CategoryContent]
      where  [Id] = #Id#
    </delete>
    <delete id="ClearContentRef" parameterClass="string" resultClass="int">
      DELETE FROM [CMS_CategoryContent]
      where  [ContentId] = #value#
    </delete>
    <!--分类操作结束-->
    <delete id="DeleteCategoryContentList" parameterClass="string" resultClass="int">
      delete from [CMS_Category] where ContentId in
      <iterate   property="IdList" open="(" close=")"  conjunction=",">
        #IdList[]#
      </iterate>

    </delete>


    <select id="GetCategoryContentByContentId" parameterClass="string" resultClass="HashTable">
      SELECT *
      FROM  [CMS_CategoryContent]
      where ContentId =  #Id#
    </select>
  </statements>
</sqlMap>